package com.xcity.robot.net.handler;

import java.util.concurrent.Executors;
import java.util.concurrent.ScheduledExecutorService;
import java.util.concurrent.ThreadFactory;

import com.xcity.pomelo.request.ChatSendRequest;
import com.xcity.robot.net.Session;
import com.xcity.robot.net.packet.PacketHandler;
import com.xcity.robot.net.util.SessionUtils;

import naga.x.net.Packet;
import naga.x.util.CommonUtils;

public class PlayerLoadResponseHandler implements PacketHandler {

	public static final PlayerLoadResponseHandler DEFAULT = new PlayerLoadResponseHandler();
	
	static final ScheduledExecutorService SCHEDULE = Executors.newScheduledThreadPool(10, new ThreadFactory() {
		@Override
		public Thread newThread(Runnable r) {
			Thread t = new Thread(r, "CHAT-SCHEDULE");
			t.setDaemon(true);
			return t;
		}
	});
	
	@Override
	public void handle(final Session session, Packet packet) {
//		System.out.println("---player load: " + packet.getData());
//		PlayerLoadResponse res = JSON.parseObject(packet.getData().toString(), PlayerLoadResponse.class);
		
//		SCHEDULE.scheduleAtFixedRate(new Runnable() {
//			@Override
//			public void run() {
				ChatSendRequest req = new ChatSendRequest();
				int len = CommonUtils.randomInt(5, 20);
				req.setContent(/*CommonUtils.randomText(len)*/String.valueOf(nextInt()));
				req.setScope("PUB");
				req.setSerial(SessionUtils.nextSerial(session));
				session.write(req);
//			}
//		}, 1, 10, TimeUnit.SECONDS);
	}
	
	static int n = 0;
	synchronized static int nextInt() {
		return ++n;
	}

}
